import axios from "axios";
import store from "@/store";
//引入进度条插件
import nProgress from "nprogress";
//引入进度条样式
import "nprogress/nprogress.css";
const requests = axios.create({
  baseURL: "/api",
  timeout: 5000,
});

requests.interceptors.request.use((config) => {
  if (store.state.Detail.uuid_token) {
    config.headers.userTempId = store.state.Detail.uuid_token;
  }
  if (store.state.User.token) {
    config.headers.token = store.state.User.token;
  }
  //进度条开始的时候
  nProgress.start();
  return config;
});

requests.interceptors.response.use(
  (res) => {
    //进度条结束的时候
    nProgress.done();
    return res.data;
  },
  (error) => {
    return Promise.reject(new Error("faile"));
  }
);
export default requests;
